
#ifndef __VOL_ODBC_DATABASE_H__
#define __VOL_ODBC_DATABASE_H__

#include <afxdb.h>

//----------------------------------------------------------------------------

struct VOL_ODBC_DATA
{
    const void* m_pData;
    INT m_nDataSize;
};

class CMyODBC;

class CVolOdbcDatabase : public CVolCommonBase
{
public:
    inline_ CVolOdbcDatabase ()
    {
        m_pdb = NULL;
    }

    inline_ ~CVolOdbcDatabase ()
    {
        CloseDatabase ();
    }

public:
    BOOL OpenDatabase (const TCHAR* szConnectString, BOOL blReadOnly, BOOL blNotShowODBCDialog);
    BOOL OpenMDB (const TCHAR* szMDBFileName, const TCHAR* szUserName, const TCHAR* szPassword, BOOL blReadOnly, BOOL blNotShowODBCDialog);
    BOOL OpenSqlServerDB (const TCHAR* szServerName, const TCHAR* szUserName, const TCHAR* szPassword, const TCHAR* szDatabaseName, BOOL blReadOnly, BOOL blNotShowODBCDialog);
    void CloseDatabase ();
    CVolString GetConnectString ();
    BOOL BeginTrans ();
    void RollbackTrans ();
    void CommitTrans ();
    INT_P OpenTable (const TCHAR* szSql, BOOL blReadonly, INT nMaxStrSize, INT nMaxBinSize);
    BOOL Requery (INT_P npTableID);
    void CloseTable (INT_P npTableID);
    BOOL IsBOF (INT_P npTableID);
    BOOL IsEOF (INT_P npTableID);
    void MoveNext (INT_P npTableID);
    void MovePrev (INT_P npTableID);
    void MoveFirst (INT_P npTableID);
    void MoveLast (INT_P npTableID);
    BOOL MoveTo (INT_P npTableID, INT nRowIndex);
    CVolComVariant& ReadColByNameOrIndex (INT_P npTableID, INT nColIndex, const TCHAR* szColName, CVolComVariant* pVar);
    BOOL ExecuteSql (const TCHAR* szSql, VOL_ODBC_DATA* pInputData, INT nInputDataCount);
    BOOL ParamExecuteSql (const TCHAR* szSql, const TCHAR* szParamTypes, ...);
    INT BDGetRecCount (INT_P npTableID);
    INT BDGetColCount (INT_P npTableID);
    const TCHAR* BDGetColText (INT_P npTableID, INT nRowIndex, INT nColIndex);
    INT BDGetColSQLType (INT_P npTableID, INT nIndex);
    BOOL BDSetColText (INT_P npTableID, INT nRowIndex, INT nColIndex, const TCHAR* szText);
    BOOL BDAppendBlank (INT_P npTableID);
    BOOL BDRemove (INT_P npTableID, INT nRecBeginIndex, INT nRecCount);
    const TCHAR* BDGetColName (INT_P npTableID, INT nColIndex);
    INT BDGetColWidth (INT_P npTableID, INT nColIndex);
    INT GetTableNames (CMStringArray& arysTabNames);
    BOOL BDGetColBin (INT_P npTableID, INT nRowIndex, INT nColIndex, CVolMem& memData);
    BOOL BDSetColBin (INT_P npTableID, INT nRowIndex, INT nColIndex, const CVolMem& memData);
    INT GetFieldIndex (INT_P npTableID, const TCHAR* lpszName);

protected:
    CMyODBC* m_pdb;
};

#endif
